/**
 * 系统用户修改js
 */
var comValidform=null;
var returnStatus=false;
var orderMutiUpdateCode={
	dataCache:null,
	duties:null,
	selectOrderIds:[],
	hasError:false,
	ivt:null,
	time:10,


	startEvent:function(){
		var parms ="";
		var checkResult=true;

		//更改职务提交
		comValidform=$(".com-addForm").Validform({
			tipSweep:true,

			beforeCheck:function(curforem){

				if(orderMutiUpdateCode.time > 0){
					return false;
				}

				params = {
					'ids': orderMutiUpdateCode.selectOrderIds.toString(),
					'recommendCode': $("#recommendCode").val().trim(),
					'actUserId': userId
				}

				if(params.actUserId == null){
					orderMutiUpdateCode.hasError = true;
					$("#errorTr").css("display", '');
					$("#errorMsg").html("登录超时，请重新登录后尝试！");
					return false;
				}

				console.log(params.recommendCode);

				if (/^1[0-9]{10}$/.test(params.recommendCode) == false) {
					orderMutiUpdateCode.hasError = true;
					$("#errorTr").css("display", '');
					$("#errorMsg").html("推荐码格式错误，只能为空或11位手机号！");
					return false;
				}


				$("#errorTr").css("display", 'none');
				$("#errorMsg").html("");

			},
			beforeSubmit:function(curform){
				$("#msgTd").html("操作进行中，请等待······");

				url = 'mgr/order/mutiUpdateCode';

				var cb = function(data){
					//成功返回
					if(data.resultCode==200){
						$("#msgTd").html("修改成功！");
						//关闭窗口并刷新数据
						alert("修改成功！");
						returnStatus=true;
					}else{
						$("#msgTd").html("");
						$("#errorTr").css("display", '');
						$("#errorMsg").html(data.msg);
					}
				};

				sendApiNoLoadSync(url, params, cb, 'POST');

				return returnStatus;
			}

		});
	},


	showSelectedOrders:function(){
		var selectedOrders=art.dialog.data('selectedOrders');  //修改id

		console.log(selectedOrders)
		orderMutiUpdateCode.selectOrderIds = selectedOrders;


		var tr ="";

		orderMutiUpdateCode.hasError = false;

		for(var i = 0; i < selectedOrders.length; i++){
			var orderId = selectedOrders[i];
			console.log("orderId = " + orderId);

			var order = eval('(' + localStorage.getItem(orderId + "_Order_Key") + ')');

			console.log(order);

			tr += '<tr><td>'
					+ (i+1)
					+ '</td><td>'
					+ order.col01id
					+ '</td><td>'
					+ order.col21userName
					+ '</td></tr>'
		}
		$('#updUserList tbody').html(tr);

		if(!orderMutiUpdateCode.hasError ){
			orderMutiUpdateCode.itv = setInterval(function(){
				$("#errorTr").css("display", '');
				$("#errorMsg").html("<h2>请在" + orderMutiUpdateCode.time +  "秒后进行操作</h2>");

				orderMutiUpdateCode.time = orderMutiUpdateCode.time - 1;

				if(orderMutiUpdateCode.time < 0) {
					clearInterval(orderMutiUpdateCode.itv);
					$("#errorTr").css("display", 'none');
				}

			}, 1000);
		}
	},
	
	init:function(){
		orderMutiUpdateCode.showSelectedOrders();
		orderMutiUpdateCode.startEvent();
	}
}
$(document).ready(function() {
	orderMutiUpdateCode.init();
});

function submitForm(){
	comValidform.submitForm();
	return returnStatus;
}

